package com.example240705;

import jakarta.persistence.Table;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Transactional
//@Repository
@Table(name = "physical_test")
public interface PhysicalRepository extends JpaRepository<PhysicalTest, Long> {
    @Query(value = "SELECT * FROM physical_test WHERE physical_test.student_id= :id ", nativeQuery = true)
    List<PhysicalTest> findAllByStudentId(@Param("id") Long id);

    //    @Query(value = "SELECT pt FROM physical_test pt WHERE pt.student_id IN :ids")
    @Query(value = "SELECT * FROM physical_test WHERE student_id IN ( :ids )", nativeQuery = true)
    List<PhysicalTest> findAllInIds(@Param("ids") List<Long> ids);

    @Transactional
    @Modifying
    @Query("DELETE FROM PhysicalTest p WHERE p.studentInfo.id = :id")
    int deleteByStudentId(@Param("id") Long student_id);

//    @Modifying
//    @Query(value = "DELETE * FROM physical_test WHERE student_id =:id ;")
//    Object deleteByStudentId(@Param("id") Long id);

//    @Query(value = "SELECT * FROM physical_test WHERE physical_test.student_id= :id",nativeQuery = true)
}